<?php 
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Member\Controller;
use \Member\Controller\InitController;
if (!defined('MODULE_CACHE')) define('MODULE_CACHE', DATA_PATH.'caches_model/');
class ProfileController extends InitController {
	public function _initialize() {
		parent::_initialize();
		$this->db = D('Member');
	}

	public function _empty() {
		$this->index();
	}

	/* 基础资料修改 */
	public function index() {
			$user= $this->db->where(array('userid'=>$this->userid))->find();
			$SEO=seo(0,"个人中心");
			include template("index");
		}
	

   //收货地址
	public function receiving(){
		if (IS_POST) {
			$info = I('post.');
			$data['city'] = $info['city'];
			$data['district'] = $info['district'];
			$data['address'] = $info['address'];
			$info['address'] =array2string($data);
			$info['code'] = $info['code'];
			$result = $this->db->update($info);
			if ($result) {
				$this->success('修改成功',U('Profile/receiving'));
			}
		}else{
			$user= $this->db->where(array('userid'=>$this->userid))->find();
			$address = string2array($user['address']);
			$city = D('Member')->getAreaName($address['city']);
		    $district = D('Member')->getAreaName($address['district']);
			$addr = $address['address'];
			$region = D('Linkage')->where(array('parentid'=>0))->select();
			$SEO=seo(0,"收货地址");
			include template("receiving");
		}

	}
	public function pwd() {
		if(IS_POST){
			$info = I('post.');
			$oldpass = md5(md5($info['oldpass'].$this->userinfo['encrypt']));
			$rs = $this->db->where(array('userid'=>$this->userid))->find();
			if($oldpass!=$rs['password']){
				$this->error('原密码错误');
			}

			if($rs){
				$info['password'] = md5(md5($info['password'].$this->userinfo['encrypt']));
				$result = $this->db->where(array('userid'=>$this->userid))->save($info);
				if(!$result){
					$this->error('修改密码失败');
				}
				$this->success('修改成功',U('Usercp/index'));
			}else{
				$this->error('该用户不存在');
			}
		}else{
			$SEO=seo(0,"修改密码");
			include template('password');
		}
	}


}